clear 

* set directory 
* cd "directory"

* set paths
global datafolder "data"
global outputfolder "output"

********************************************************************************
*			Figure 7: Alternative definitions of subsidization
********************************************************************************
	
* Alternative subsidy definitions
use "$datafolder\maindata.dta", clear
		
	keep if datem >= 660
	
	gen ar_belowprime = actual_rate < prime_rate
		
	gen int_cov_b1 = (EBIT/InterestExpensePL) < 1 ///
		& (EBIT_l1/InterestExpense_l1) <1

	* The BE approach
	gen below_BE = actual_rate < theoretical_rate
	
	egen dateqid = group(dateq)
	
	gen diag_line = _n
	
	
	* Create jittered points with only negative noise
	gen actual_rate_jit = actual_rate -  rnormal(0.5, 0.25) ///
		if ar_belowprime==1 | int_cov_b1==1 | below_BE==1 
	gen theoretical_rate_jit = theoretical_rate +  rnormal(0.5, 0.25) ///
		if ar_belowprime==1 | int_cov_b1==1 | below_BE==1 
		
	replace actual_rate_jit = 0 if actual_rate_jit < 0
	

	twoway (scatter actual_rate_jit theoretical_rate_jit  ///
	if below_BE==1, yscale(range(0 25)) ylabel(0(5)25, angle(horizontal)) ///
	graphregion(color(white)) color(cranberry) mfcolor(none)  msymbol(O)  ) ///
	(scatter actual_rate_jit theoretical_rate_jit  ///
	if int_cov_b1==1, color(ebblue) mfcolor(none)  msymbol(X) ) /// 
	(scatter actual_rate_jit theoretical_rate_jit  ///
	if ar_belowprime==1, color(emerald) mfcolor(none) msymbol(T) /// 
	legend(pos(10) ring(0) order(1 2 3)  lab(1 "Below BE") ///
	lab(2 "Interest coverage<1") lab(3 "Below prime rate") region(lcolor(white) fcolor(none))  ) )  ///
	(line diag_line diag_line if diag_line<25, color("red") lpattern("--") ///
	xtitle("Breakeven Rate") ytitle("Actual Rate") )	
		

	graph export "$outputfolder\figure_7.pdf", as(pdf) replace
	graph export "$outputfolder\figure_7.png", as(png) replace
	
	
	